package com.lc.pianostudent.conn;

import com.lc.pianostudent.bean.CircleBean;
import com.lc.pianostudent.bean.CommentsBean;
import com.lc.pianostudent.bean.ContentImgBean;
import com.lc.pianostudent.bean.PraiseBean;
import com.lc.pianostudent.bean.UpListBean;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.net.ContentHandler;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/2/22.
 */
@HttpInlet(Conn.MAIL_GETCONTENT)
public class PostGetContent extends BaseAsyPost {

    public String id,user_id;
    public PostGetContent(AsyCallBack asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected PostGetContentInfo parser(JSONObject object) throws Exception {
        if (object.optString("code").equals("200")) {

            PostGetContentInfo info = new PostGetContentInfo();

            info.code = object.optString("code");
            JSONObject jsonObject = object.optJSONObject("data");
            info.id = jsonObject.optString("id");
            info.userid = jsonObject.optString("userid");
            info.content = jsonObject.optString("content");
            info.create_time = jsonObject.optString("create_time");
            info.up = object.optString("up");
            JSONObject jsonObject1 = object.optJSONObject("user");
            info.avatar = jsonObject1.optString("avatar");
            info.listup = object.optString("listup");
            info.name = jsonObject1.optString("name");
            info.upcheck = object.optString("upcheck");

            JSONArray array = jsonObject.optJSONArray("picarr");
            if(array != null || array.length() != 0){
                for(int i = 0;i<array.length();i++){
                    JSONObject o = array.optJSONObject(i);
                    info.imgList.add(o.optString("img"));
                }
            }

            array = object.optJSONArray("uplist");
            if(array != null || array.length() != 0){
                for(int i = 0;i<array.length();i++){
                    JSONObject o = array.optJSONObject(i);
                    CircleBean.ListBean.UplistBean upListBean = new CircleBean.ListBean.UplistBean();
                    upListBean.setName(o.optString("name"));
                    upListBean.setUserid(o.optInt("userid"));
                    info.praiseList.add(upListBean);
                }
            }

            array = object.optJSONArray("list");
            if(array != null || array.length() != 0){
                for(int i = 0;i<array.length();i++){
                    JSONObject o = array.optJSONObject(i);
                    CommentsBean commentsBean = new CommentsBean();
                    commentsBean.setName(o.optString("name"));
                    commentsBean.setUserid(o.optString("userid"));
                    commentsBean.setContent(o.optString("content"));
                    commentsBean.setFromid(o.optString("fromid"));
                    commentsBean.setFromname(o.optString("fromname"));
                    commentsBean.setId(o.optString("id"));
                    commentsBean.setType(o.optString("type"));
                    commentsBean.setFromuserid(o.optString("fromuserid"));
                    info.commentList.add(commentsBean);
                }
            }


            TOAST = object.optString("message");
            return info;

        } else {

            TOAST = object.optString("message");

        }

        return null;
    }

    public static class PostGetContentInfo {

        public String code,id,userid,content,create_time,up,avatar,name,listup,upcheck;
        public List<String> imgList = new ArrayList<>();
        public List<CircleBean.ListBean.UplistBean> praiseList = new ArrayList<>();
        public List<CommentsBean> commentList = new ArrayList<>();

    }

}
